package com.me.web;

import com.me.pojo.Pokemon;
import com.me.pojo.Trainer;
import com.me.service.PokemonService;
import com.me.service.TrainerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/selecttrainerbyidServlet")
public class selecttainerbyidServlet extends HttpServlet {
    //1.调用PokemonService获取所有Pokemon
    TrainerService service = new TrainerService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收id
        String id = request.getParameter("id");
        //2.调用service查询
        Trainer trainer = service.selecttrainerbyid(Integer.parseInt(id));
        //2.将Pokemon放入request
        request.setAttribute("trainer",trainer);
        //3.转发到pokemon.jsp
        request.getRequestDispatcher("/updatetrainer.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
